import { Component } from '@angular/core';
import { ICellRendererAngularComp } from '@ag-grid-community/angular';
import { ApesContextMenuService } from '@shared/ag-grid-ext/context-menu';

@Component({
  selector: 'apes-cell-dialog',
  template: `
    <div class="apes-cell-dialog" (click)="showDialog()">{{inputValue}}</div>
  `,
  styles: [],
})
export class RenderDialogComponent implements ICellRendererAngularComp {
  params;
  inputValue;

  constructor(private contextService: ApesContextMenuService) {
  }

  refresh(params: any): boolean {
    return false;
  }

  agInit(params: any): void {
    this.params = params;
    // if (this.params.value) {
    this.inputValue = this.params.value;
    // } else {
    //   this.inputValue = this.params.colDef.cellEditorParams.value;
    // }
  }

  showDialog() {
    let context = this.contextService;
    let key = this.params.column.colId;
    let api = this.params.colDef.cellEditorParams.api;
    let data = this.params.node.data;
    // console.log(this.params);
    // context.openContextDynamicDailog(data, api, key, this.dialogAfter(),null,ApesFormComponent);
    context.openContextDynamicDailog(data, api, key, this.dialogAfter());
  }

  dialogAfter() {
    // console.log('完成');
  }
}
